package cn.mysource.org.controller;

import cn.mysource.basic.config.BussinessException;
import cn.mysource.org.domain.ShopAuditLog;
import cn.mysource.org.query.PermissionQuery;
import cn.mysource.org.service.IShopService;
import cn.mysource.org.domain.Shop;
import cn.mysource.basic.util.AjaxResult;
import cn.mysource.basic.util.PageList;
import cn.mysource.org.vo.AuditShopVo;
import cn.mysource.org.vo.ShopSettlementVo;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    public IShopService shopService;


    /**
     * 保存和修改公用的
     * @param shop  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Shop shop){
        try {
            if( shop.getId()!=null)
                shopService.update(shop);
            else
                shopService.add(shop);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("保存对象失败！" + e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public Shop get(@PathVariable("id")Long id)
    {
        return shopService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<Shop> list(){

        return shopService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<Shop> json(@RequestBody PermissionQuery query)
    {
        return shopService.queryByPage(query);
    }
    @PostMapping("/settlement")
    public AjaxResult settlement(@RequestBody @Valid ShopSettlementVo vo)
    {
        shopService.settlement(vo);
        return AjaxResult.me().success();
    }
//    @PostMapping("/audit/pass")
//    Public AjaxResult auditPass(@RequestBody @Valid AuditShopVo vo){
//
//                shopService.auditPass(vo);
//                return AjaxResult.me().success();
//
//
//
//
//    }
//    @GetMapping("/active/{id}")
//    Public AjaxResult active(@PathVariable("id") Long id) {
//
//        shopService.active(id);
//        return AjaxResult.me().success();
//    }

}
